package com.ftg.learn.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ftg.learn.entity.sys.Resources;
import com.ftg.learn.entity.sys.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 用户mapper处理
 *
 * @author kangjx
 * @date 2022/10/21
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 用来判断当前组定的用户 名与密码是否存在
     * @param account   账号
     * @param password  密码
     * @return  User|null
     */
    @Select("select * from sys_user where is_deleted = 0 and u_account=#{account} and u_password=#{password}")
    @Results({
            @Result(column = "u_account",property = "uaccount")
    })
    User loginForUser(
            @Param("account") String account,
            @Param("password") String password
    );

    /**
     * 当前用户的主键查询权限
     * @param uid  用户 编号
     * @return List<Resources>
     */
    @Select("select distinct * " +
            "from sys_resources " +
            "where id in (select res_id " +
            "             from sys_role_resources " +
            "             where r_id in ( " +
            "                 select r_id " +
            "                 from sys_user_role " +
            "                 where u_id = #{uid} and is_deleted = 0 " +
            "             ) " +
            "               and is_deleted = 0) " +
            "  and is_deleted = 0;")
    List<Resources> showProvilegeWithUid(@Param("uid") int uid);

}
